/*************************************************************************
 *
 * definice a inicializace globalnich dat
 * 
 * (c) Ales Povalac, alpov@alpov.net, http://www.alpov.net/
 * 
 *************************************************************************
 *
 * $Id: data.c 62 2006-07-27 16:54:30Z alpov $
 * 
 *************************************************************************/         

#include <stdint.h>
#include <avr/pgmspace.h>
#include <avr/eeprom.h>
#include "../avrx/avrx.h"
#include "../avrx/AvrXFifo.h"
#include "data.h"

//Mutex DataLock;

EEDATA_STRUCT EEPROM eedata = {
    .sensor_count = 2,
    .sensors = {
        {0x10,0x55,0x10,0x9f,0x00,0x08,0x00,0x4f},
        {0x28,0x50,0x24,0x82,0x00,0x00,0x00,0x09}
    },
    .term_addr = 3,
    .rtc_deviation = 0
};

STDATA_STRUCT stdata;

RWDATA_STRUCT rwdata = {
    .mode = 1,
    .shift = -10,
    .shift_length = 12,
    .sw_mode = 2,
    .sw_datetime = 212954400,
    .now = 181418400       
};


/*************************************************************************
 * nacteni bloku z eeprom (napr. textu)
 *************************************************************************/ 
void ReadEEPromBlock(void *pointer_ram, void *pointer_eeprom, unsigned char n)
{
    AvrXWaitSemaphore(&EEPromMutex);
    eeprom_busy_wait();
    eeprom_read_block(pointer_ram, pointer_eeprom, n);
    AvrXSetSemaphore(&EEPromMutex);
}


/*************************************************************************
 * zapis bloku do eeprom (napr. textu)
 *************************************************************************/ 
void WriteEEPromBlock(void *pointer_ram, void *pointer_eeprom, unsigned char n)
{
    AvrXWaitSemaphore(&EEPromMutex);
    eeprom_busy_wait();
    eeprom_write_block(pointer_ram, pointer_eeprom, n);
    AvrXSetSemaphore(&EEPromMutex);
}

